package com.fwtai.controller.web;

import com.fwtai.bean.PageFormData;
import com.fwtai.service.web.CarouselService;
import com.fwtai.tool.ToolClient;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 轮播图控制层|路由层
 * @作者 田应平
 * @版本 v1.0
 * @QQ号码 444141300
 * @创建日期 2022-06-01 16:02:15
 * @官网 <url>http://www.fwtai.com</url>
*/
@RestController
@RequestMapping("/carousel")
public class CarouselController{

  private final CarouselService carouselService;

  public CarouselController(final CarouselService carouselService){
    this.carouselService = carouselService;
  }

  /**添加*/
  @PreAuthorize("hasAuthority('carousel_btn_add')")
  @PostMapping("/add")
  public void add(final HttpServletRequest request,final HttpServletResponse response){
    ToolClient.responseJson(carouselService.add(request),response);
  }

  /**编辑*/
  @PreAuthorize("hasAuthority('carousel_row_edit')")
  @PostMapping("/edit")
  public void edit(final HttpServletRequest request,final HttpServletResponse response){
    ToolClient.responseJson(carouselService.edit(request),response);
  }

  /**根据id查询对应的数据*/
  @PreAuthorize("hasAuthority('carousel_row_queryById')")
  @GetMapping("/queryById")
  public void queryById(final Long id,final HttpServletResponse response){
    ToolClient.responseJson(carouselService.queryById(id),response);
  }

  /**隐藏*/
  @PreAuthorize("hasAuthority('carousel_row_delById')")
  @PostMapping("/delById")
  public void delById(final Long id,final HttpServletResponse response){
    ToolClient.responseJson(carouselService.delById(id),response);
  }

  /**删除数据*/
  @PreAuthorize("hasAuthority('carousel_row_delData')")
  @PostMapping("/delData")
  public void delData(final Long id,final HttpServletResponse response){
    ToolClient.responseJson(carouselService.delData(id),response);
  }

  /**显示*/
  @PreAuthorize("hasAuthority('carousel_row_editEnable')")
  @PostMapping("/editEnable")
  public void editEnable(final Long id,final HttpServletResponse response){
    ToolClient.responseJson(carouselService.editEnable(id),response);
  }

  /**批量隐藏*/
  @PreAuthorize("hasAuthority('carousel_btn_delByKeys')")
  @PostMapping("/delByKeys")
  public void delByKeys(final String ids,final HttpServletResponse response){
    ToolClient.responseJson(carouselService.delByKeys(ids),response);
  }

  /**获取数据*/
  @PreAuthorize("hasAuthority('carousel_btn_listData')")
  @GetMapping("/listData")
  public void listData(final HttpServletRequest request,final HttpServletResponse response){
    ToolClient.responseJson(carouselService.listData(new PageFormData(request)),response);
  }
}